This step-by-step tutorial will guide you to build a complete C# application that analyzes 1D barcodes using the command line and a text editor, like Visual Studio Code.
Copy Code | |
---|---|
mkdir MyProject
dotnet new console |
MyProject.csproj |
Copy Code |
---|---|
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp2.1</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include="System.Drawing.Common" Version="4.5.0" /> <PackageReference Include="Accusoft.BarcodeXpress13.NetCore.dll" Version="13.2.1350" /> </ItemGroup> </Project> |
You will need System.Drawing.Bitmap to load an image and pass it to Barcode Xpress for processing.
If you would like to use a local copy of Barcode Xpress instead of fetching one from Nuget, you can use an ItemGroup containing a reference instead of the PackageReference above:
Copy Code<ItemGroup> <Reference Include="Accusoft.BarcodeXpress.NetCore"> <HintPath>..\BarcodeXpress\Accusoft.BarcodeXpress13.NetCore.dll</HintPath> </Reference> </ItemGroup>
Additionally, add the using statements for System.Drawing and BarcodeXpressSdk to the top of your generated Program class:
Program.cs Copy Code using System; using System.Drawing; using Accusoft.BarcodeXpressSdk; namespace MyProject { ...
Program.cs |
Copy Code |
---|---|
… namespace MyProject { class Program { static void Main(string[] args) { BarcodeXpress barcodeXpress = new BarcodeXpress(); } } } |
Program.cs |
Copy Code |
---|---|
… namespace MyProject { class Program { static void Main(string[] args) { BarcodeXpress barcodeXpress = new BarcodeXpress(); Bitmap bitmap = new Bitmap("barcode.bmp"); Accusoft.BarcodeXpressSdk.Result[] results = barcodeXpress.reader.Analyze(bitmap); } } } |
Program.cs |
Copy Code |
---|---|
… namespace MyProject { class Program { static void Main(string[] args) { BarcodeXpress barcodeXpress = new BarcodeXpress(); Bitmap bitmap = new Bitmap("barcode.bmp"); Accusoft.BarcodeXpressSdk.Result[] results = barcodeXpress.reader.Analyze(bitmap); if (results.Length > 0) { foreach (Accusoft.BarcodeXpressSdk.Result result in results) { Console.WriteLine("{0} : {1}", result.BarcodeType.ToString(), result.BarcodeValue); } } else { Console.WriteLine("No Barcodes Found."); } } } } |
Program.cs |
Copy Code |
---|---|
… namespace MyProject { class Program { static void Main(string[] args) { BarcodeXpress barcodeXpress = new BarcodeXpress(); Bitmap bitmap = new Bitmap("barcode.bmp"); Accusoft.BarcodeXpressSdk.Result[] results = barcodeXpress.reader.Analyze(bitmap); if (results.Length > 0) { foreach (Accusoft.BarcodeXpressSdk.Result result in results) { Console.WriteLine("{0} : {1}", result.BarcodeType.ToString(), result.BarcodeValue); } } else { Console.WriteLine("No Barcodes Found."); } barcodeXpress.Dispose(); } } } |